<?php


#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("../include/author.php5");
include_once ("../include/config.inc");
include_once ("../include/template.inc");
include_once ("../include/class.db.php5");
include_once ("../include/class.tools.php5");
include_once ("./tools.php5");
include_once ("../dataAccess/classes/Image.php5");
include_once ("../dataAccess/dao/ImageDAO.php5");

$svo = new db("svoptik");
$tools = new tool();
include_once ("../include/global_fix_intern.inc");

define("EXTENSIONS", "png jpeg jpg gif PNG JPEG JPG GIF");
#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik.tpl",
	"navi" => "navi.tpl",
	"gallery_new" => "gallery_new.tpl"
));
#--------------------------------------------------

#--------------------------------------------------
# CREATE NAVIGATION RIGHT
#--------------------------------------------------
$links = "";
$url[0] = array (
	"URL" => "",
	"URL-TEXT" => "",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
for ($i = 0; $i < count($url); $i++) {
	$links .= "
				        <tr height=\"15\">
							<td valign=\"top\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
							<td valign=\"top\"><a href=\"" . $url[$i]['URL'] . "\" class=\"sitenav\" target=\"" . $url[$i]['TARGET'] . "\" onClick=\"" . $url[$i]['ONCLICK'] . "\">" . $url[$i]['URL-TEXT'] . "</a></td>
							<td valign=\"top\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
						</tr>
						<tr height=\"15\">
				            <td colspan=\"3\"><img src=\"../standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
						</tr>
				       ";
}
include_once ("../member/standard/navi.php5");
$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner,
	"JSNAVI" => $js_navi
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "NEW REPORT"
#--------------------------------------------------
if ($usr_priv > 2) {
	// MASKE LADEN
	if ($send) {
		$title = trim($title);
		if (!empty($title)){
			$gallery = new GalleryVO(0);
			$gallery->title = $title;
			$gallery->description = $description;
			$gallery->location = $location;
			
			$dao = new ImageDAO();
			if ($dao->createGallery($gallery, $usr_id)){
				$msg = "Galerie \"" . $gallery->title . "\" wurde erfolgreich angelegt.";
				$target = "galleries";
			}
			
			$msg = "<script language=\"javascript\" type=\"text/javascript\">alert('" . $msg . "');window.location.replace('" . $target . ".php5');</script>";

			$t->set_var(array (
				"ID" => 0,
				"TITLE" => $title,
				"DESCRIPTION" => $description,
				"LOCATION" => $location,
				"MSG" => $msg
			));
			$content .= $t->parse("", "gallery_new", true);
			
		} else {
			$t->set_var(array (
				"ID" => 0,
				"TITLE" => $title,
				"DESCRIPTION" => $description,
				"LOCATION" => $location,
				"MSG" => "<script language=\"javascript\" type=\"text/javascript\">alert('Bitte einen Titel angeben!');</script>"
			));
			$content .= $t->parse("", "gallery_new", true);
		}
	} else {
		$t->set_var(array (
			"ID" => 0,
			"TITLE" => "",
			"DESCRIPTION" => "",
			"LOCATION" => "",
			"MSG" => "",
		));
		$content .= $t->parse("", "gallery_new", true);
	}
	
} else
	$content = "
	  <script language=\"javascript\">
	  <!--
	  alert('Du besitzt leider nicht die erforderlichen Rechte,\\num diese Seite anzeigen zu lassen!');
	  window.location.replace('index.php5');
	  //-->
	  </script>
	  ";
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => "MEMBERAREA -> <a href=\"galleries.php\" class=\"sitenav\" target=\"_self\">GALERIE</a> -> NEU ERFASSEN",
	"content" => $content . "<br>",
	"navi" => $right_nav,
	"FORM_TARGET" => "gallery_new.php5"
));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
